package com.zhouyibike.uu.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

/**
 * @author Jungly
 * jungly.ik@gmail.com
 * 15/3/8 10:07
 */
public class Util {

    public static int px2sp(Context context, float pxValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 0.5f);
    }

    public static int dp2px(Context context, int dp) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        return (int) ((dp * displayMetrics.density) + 0.5);
    }
    public static void setLviewwh(View view, double w, double h, double pinmukuan){
        LinearLayout.LayoutParams lp= (LinearLayout.LayoutParams) view.getLayoutParams();
        double scale=h/w;
        lp.width= (int) (DataSingle.getInstance().PhoneW*pinmukuan);
        lp.height= (int) (DataSingle.getInstance().PhoneW*pinmukuan*scale);
        view.setLayoutParams(lp);
    }
    public static void setLviewwh2(View view, double w, double h, double pinmukuan,int x){
        LinearLayout.LayoutParams lp= (LinearLayout.LayoutParams) view.getLayoutParams();
        double scale=h/w;
        lp.width= (int) (DataSingle.getInstance().PhoneW*pinmukuan)-x;
        lp.height= (int) ((DataSingle.getInstance().PhoneW*pinmukuan-x)*scale);
        view.setLayoutParams(lp);
    }
    public static void setRviewwh(View view, double w, double h, double pinmukuan){
        RelativeLayout.LayoutParams lp= (RelativeLayout.LayoutParams) view.getLayoutParams();
        double scale=h/w;
        lp.width= (int) (DataSingle.getInstance().PhoneW*pinmukuan);
        lp.height= (int) (DataSingle.getInstance().PhoneW*pinmukuan*scale);
        view.setLayoutParams(lp);
    }
    public static void setLtitle(View view, double w, double h,int needheight){
        LinearLayout.LayoutParams lp= (LinearLayout.LayoutParams) view.getLayoutParams();
        double  scale=w/h;
        lp.width= (int) (needheight*scale);
        lp.height= needheight;
        view.setLayoutParams(lp);
    }
    public static void setRtitle(View view, double w, double h,int needheight){
        RelativeLayout.LayoutParams lp= (RelativeLayout.LayoutParams) view.getLayoutParams();
        double scale=w/h;
        lp.width= (int) (needheight*scale);
        lp.height= needheight;
        view.setLayoutParams(lp);
    }

}
